package com.hhkj.admin.order.common.component.checker;

import cn.hutool.core.collection.CollectionUtil;
import com.hhkj.admin.order.common.component.validator.OrderValidator;
import com.hhkj.admin.order.domain.Order;
import com.hhkj.admin.order.domain.OrderItem;
import com.hhkj.admin.order.model.dopo.OrderItemDo;
import com.hhkj.admin.order.model.dopo.OrderItemPo;
import com.hhkj.admin.order.service.base.OrderItemService;
import com.hhkj.admin.order.service.extend.OrderExtendService;
import com.ruoyi.common.base.model.extend.ValidError;
import com.ruoyi.common.exception.GlobalErrorListException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class OrderChecker {

    @Autowired
    private OrderExtendService orderExtendService;

    @Autowired
    private OrderItemChecker orderItemChecker;

    /**
     * 只校验订单是否合格
     * @param orderId
     * @return
     */
    public Order checkBeforePayOrder(Long orderId) {
        Order order = orderExtendService.getByIdNotNull(orderId);
        //是否是待支付的订单
        OrderValidator.isPendingOrder(order);
        return order;
    }

    /**
     * 既校验订单，也校验订单item是否合格
     * @param orderId
     * @return
     */
    public Order checkOrderAndItemBeforePayOrder(Long orderId) {
        Order order = orderExtendService.getByIdNotNull(orderId);
        //是否是待支付的订单
        OrderValidator.isPendingOrder(order);
        //校验子订单
        orderItemChecker.checkBeforePayOrder(orderId);
        return order;
    }
}
